
#include "bsp.h"


unsigned char seg7Code[16] = {0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0, 0xFE, 0xF6};
unsigned char Disp_data[8] = {0, 0, 2, 1, 1, 9, 9, 9};



const unsigned char zdhz[][32] = {
{0x00,0x0C,0x18,0x18,0x00,0x00,0xFF,0x18,0x18,0x18,0x18,0x18,0x78,0x38,0x18,0x00,0x06,0x06,0x06,0x06,0x06,0x06,0xFF,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06,0x06},/*"璁?",0*/
{0x30,0xF8,0x1F,0x18,0x18,0xFF,0x18,0x3C,0x7C,0x1E,0xDE,0x1B,0x18,0x18,0x18,0x18,0x18,0x19,0x1B,0x1B,0x18,0x19,0x1B,0x1B,0x18,0xF8,0x1F,0x18,0x18,0x18,0x18,0x18}/*"绉?",1*/
};



void hc595Send(unsigned char data)
{
	bsp_spiWrite0(data);	
}

void segSelect(char index)
{
	GPIOE->ODR &= ~(0x0f<<12);
	GPIOE->ODR |= index<<12;
}

void dzFlash(void)
{
  static int  dzIndex = 0;
	DZ595_DISable();
	hc595Send(zdhz[1][ dzIndex + 16]);
	hc595Send(zdhz[1][ dzIndex]);
	hc595Send(zdhz[0][ dzIndex + 16]);
	hc595Send(zdhz[0][ dzIndex]);
	DZ_ST_CLK();
	segSelect(dzIndex);
	DZ595_Enable();
	dzIndex++;
	if (dzIndex > 15)
		dzIndex = 0;
}
void segFlash(void)
{
  static int  segIndex = 0;
 	SEG595_DISable();
	hc595Send(seg7Code[Disp_data[segIndex]]);
	SEG_ST_CLK();
	segSelect(segIndex);
	SEG595_Enable();
	segIndex++;
	if (segIndex > 7)
		segIndex = 0;
}


void seg_dz_GPIOInit(void)
{	
	
	GPIO_InitTypeDef GPIO_InitStructure;
	/* 打开GPIO时钟 */
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOE, ENABLE);


	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;	/* 推挽输出模式 */
	
	
	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_9|GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12|GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
	GPIO_Init(GPIOE, &GPIO_InitStructure);
	
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
	GPIO_Init(GPIOD, &GPIO_InitStructure);
	
	
	DISP_Enable();
	SEG595_Enable();
}

